/**
 * 
 */
package dms.dto;

import java.text.ParseException;
import java.util.Date;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import dms.util.DateFormatUtil;

/**
 * @author 李健
 *
 */
public class MailDTO extends ActionForm {
	private Long id;
	
	private String student;
	
	private String dormitory;
	
	private String description;
	
	private String arriveDate;
	
	private String fromDate;
	
	private String toDate;
	
	private String query;
	
	private String type;

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getFromDate() {
		return fromDate;
	}

	public void setFromDate(String fromDate) {
		this.fromDate = fromDate;
	}

	public String getToDate() {
		return toDate;
	}

	public void setToDate(String toDate) {
		this.toDate = toDate;
	}

	public String getQuery() {
		return query;
	}

	public void setQuery(String query) {
		this.query = query;
	}

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}


	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * @return the arriveDate
	 */
	public Date getArriveDate() {
		try {
			return DateFormatUtil.parseDate(arriveDate);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * @param arriveDate the arriveDate to set
	 */
	public void setArriveDate(String arriveDate) {
		this.arriveDate = arriveDate;
	}

	/**
	 * @return the dormitory
	 */
	public String getDormitory() {
		return dormitory;
	}

	/**
	 * @param dormitory the dormitory to set
	 */
	public void setDormitory(String dormitory) {
		this.dormitory = dormitory;
	}

	/**
	 * @return the student
	 */
	public String getStudent() {
		return student;
	}

	/**
	 * @param student the student to set
	 */
	public void setStudent(String student) {
		this.student = student;
	}
	
	@Override
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		this.arriveDate = null;
		this.description = null;
		this.dormitory = null;
		this.fromDate = null;
		this.id = null;
		this.query = null;
		this.student = null;
		this.toDate = null;
		
	}
	
	@Override
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		ActionErrors errors = new ActionErrors();
		
		if (this.student == null || this.student.length() == 0) {
			errors.add("student", new ActionMessage("缺少学生", false));
		}
		if(this.dormitory == null || this.dormitory.length() == 0) {
			errors.add("dormitory", new ActionMessage("缺少寝室", false));
		}
		if (this.description == null || this.description.length() == 0) {
			errors.add("description", new ActionMessage("缺少内容", false));
		}
		
		if (!errors.isEmpty()) {
			request.setAttribute("status", false);
			request.setAttribute("message", "缺少信息");
		}
		return errors;
		
	}
}
